﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Xml.Serialization;

namespace ForumBrowser.Models
{
    public static class RssReader
    {
        public static RssFeed Read(string url)
        {
            RssFeed rssFeed = null;

            WebClient myWebClient = new WebClient();
            byte[] rssBuffer = myWebClient.DownloadData(url);
            string rssText = Encoding.ASCII.GetString(rssBuffer);

            using (TextReader s = new StringReader(rssText))
            {
                var deserializer = new XmlSerializer(typeof(RssFeed));
                rssFeed = deserializer.Deserialize(s) as RssFeed;
            }
            return rssFeed;
        }
    }
}